package com.mz.mattress.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mz.mattress.admin.api.resp.BonusSum;
import com.mz.mattress.admin.api.resp.BonusDaySum;
import com.mz.mattress.api.entity.OrderUseTimesBonus;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface OrderUseTimesBonusMapper extends BaseMapper<OrderUseTimesBonus> {

//    @Select("SELECT dates,count(*) count,sum(bonus) sumBonus from mz_order_use_times_bonus where months=#{months} and member_id=#{memberId} GROUP BY dates desc")
//    List<BonusDaySum> listMonths(@Param("memberId") Long memberId, @Param("months") String months);

    List<BonusDaySum> listMonths(@Param("memberId") Long memberId,
                                 @Param("months") String months,
                                 @Param("type") Integer type,
                                 @Param("typeId") Integer typeId);

    IPage<OrderUseTimesBonus> listPage(Page page,
                                       @Param("months") String months,
                                       @Param("dates") String dates,
                                       @Param("memberId") Long memberId,
                                       @Param("type") Integer type,
                                       @Param("typeId") Integer typeId);

    Integer listPageSum(
            @Param("months") String months,
            @Param("dates") String dates,
            @Param("memberId") Long memberId,
            @Param("type") Integer type,
            @Param("typeId") Integer typeId);


    @Select("select * from mz_order_use_times_bonus where record_id=#{recordId} and deleted=0")
    List<OrderUseTimesBonus> selectByRecordId(@Param("recordId") Integer recordId);

//    @Select("SELECT sum(bonus) from mz_order_use_times_bonus where type=#{type} and type_id=#{typeId} and months=#{months}")

    Integer selectSum(@Param("type") Integer type,
                      @Param("typeId") Integer typeId,
                      @Param("memberId") Long memberId,
                      @Param("months") String months);

    Integer selectMemberCount(@Param("type") Integer type,
                              @Param("typeId") Integer typeId,
                              @Param("memberId") Long memberId,
                              @Param("startTime") String startTime);

    BonusSum selectBonusSum(@Param("type") Integer type,
                            @Param("typeId") Integer typeId,
                            @Param("memberId") Long memberId,
                            @Param("startTime") String startTime);

    @Update("update mz_order_use_times_bonus set mobile=#{saleMobile} where type in (2,3) and type_id=#{saleId}")
    Integer updateSaleMobile(@Param("saleId") Integer saleId, @Param("saleMobile") String saleMobile);

}
